<template>
	<view class="p30">
		<cust-empty desc="暂无数据" v-if="loadStatus=='none'">
		</cust-empty>
		<u-checkbox-group v-model="selection" activeColor="#06B7F3" placement="column">
			<view v-if="show" @longpress="showSelect" v-for="item in list" :key="item.id">
				<feedback>
					<template v-slot:header>
						<view class="flex-between-center">
							<view>{{item.createTime}}</view>
							<view>
								<u-checkbox v-if="selectMode" :name="item.id" shape="circle" label="选中"></u-checkbox>
							</view>
						</view>
					</template>
					<template v-slot:content>
						<view class="ptb30 pt10" :class="[item.customerAttachList && item.customerAttachList.length ? 'bb' : '']">
							{{item.content}}
						</view>
						<view class="flex-wrap ptb30" v-if="item.customerAttachList && item.customerAttachList.length">
							<view class="mr20 border" v-for="(attach,index) in item.customerAttachList" :key="attach.id"
								@click="previewImageFun(index,item.customerAttachList)">
								<image :src="attach.link" style="width: 40px;height: 40px;"></image>
							</view>
						</view>
					</template>
				</feedback>
			</view>
		</u-checkbox-group>
		<view class="nomore" v-if="loadStatus != 'none'">
			<u-loadmore :status="loadStatus" />
		</view>
		<!-- <view v-if="!selectMode" class="flex-center" :class="[list.length?'cust-fix-bottom':'']"> -->
			<!-- <view :class="[list.length?'bottom-box':'mt100']"> -->
			<view v-if="!selectMode" class="flex-center cust-fix-bottom">
				<view class="bottom-box">
				<u-button :customStyle="{width: '150px'}" type="primary" text="新增反馈建议" :throttleTime="1000" @click="toAdd">
				</u-button>
			</view>
		</view>
		<view v-if="selectMode" class="h140"></view>
		<fix-bottom-del v-if="selectMode" @cancel="handleCancel" @del="showDelConfirmDia"></fix-bottom-del>
		<u-modal :show="delConfirmDia" :title="delConfirmDiaTitle" :content="delConfirmDiaContent"
			:confirmText="delConfirmDiaYesBtn" :showCancelButton="true" :cancelText="delConfirmDiaNoBtn"
			@confirm="handleDel" @cancel="hideDelConfirmDia"></u-modal>

	</view>
</template>

<script>
	import Feedback from "../components/feedback";
	import FixBottomDel from "../components/fix-bottom-del";
	import delConfirm from "@/mixins/delConfirm";
	import custEmpty from "@/components/cust-empty/index.vue"
	import {
		getFeedbackListAPI,
		removeFeedbackAPI
	} from "@/api/api/feedback";
	import pages from "@/mixins/pages.js";
	import {
		throttle
	} from '@/utils/utils.js'

	export default {
		components: {
			FixBottomDel,
			Feedback,
			custEmpty
		},
		mixins: [delConfirm, pages],
		data() {
			return {
				isRefresh:true,
				show: true,
				selection: [],
				selectMode: false,
				funAPI: ''
			}
		},
		onShow() {
			if(this.isRefresh){
				this.funAPI = getFeedbackListAPI;
				this.showPropListCallcack= (obj,item)=>{
					return {
						id:item.id,
						createTime:item.createTime,
						customerAttachList:item.customerAttachList,
						content:item.content
					}
				};
				this.initList();
				this.getListFun();
				this.isRefresh=false;
			}
		},
		methods: {
			toAdd:throttle(function(){
				this.$navigateTo('/pagesMy/views/feedbackForm');
			}),
			previewImageFun:throttle(function(index, list){
				let photoList = list.map(item => { // item 获取到的图片地址
					return item.link;
				});
				uni.previewImage({
					current: index, // 当前显示图片的索引值
					urls: photoList, // 需要预览的图片列表，photoList要求必须是数组
				})
			}),
			handleChange(e) {
				console.log(e)
			},
			showSelect() {
				this.selectMode = true
			},
			handleCancel() {
				this.selection = []
				this.selectMode = false
			},
			handleDel() {
				this.hideDelConfirmDia()
				removeFeedbackAPI(this.selection.join(",")).then(([err, data]) => {
					if (err) return;
					this.initList();
					uni.showToast({
						title: '删除成功'
					});
					this.getListFun();
				})
				this.handleCancel()
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .u-checkbox{
		height: 24px;
		width: 55px;
		justify-content: center;
		position: relative;
		transform: translateX(10px);
		&>text{
			transform: scale(2);
			position: absolute;
			left: 10px;
			color: #ffffff00 !important;
			z-index: 3;
		}
	}
</style>
